#include "CFDEntropyProductionPostprocessor.h"
#include "CFDProblem.h"

template<>
InputParameters validParams<CFDEntropyProductionPostprocessor>()
{
  InputParameters params = validParams<ProblemElementalL2Error>();
  params.addRequiredParam<PostprocessorName>("volume", "The name of the postprocessor");
  return params;
}

CFDEntropyProductionPostprocessor::CFDEntropyProductionPostprocessor(const InputParameters &parameters) :
	ProblemElementalL2Error(parameters),
	_gamma(_cfd_problem._gamma),
	_mach(_cfd_problem._mach),
	_s_inf(1./_gamma/_mach/_mach),
    _volume(getPostprocessorValue("volume"))

{
}

Real CFDEntropyProductionPostprocessor::getValue()
{
  return std::sqrt(ElementIntegralPostprocessor::getValue())/_volume;
}

Real CFDEntropyProductionPostprocessor::computeQpIntegral()
{
	for (size_t i = 0; i < _uh.size(); ++i)
	{
		_cfd_data.uh[i] = (*_uh[i])[_qp];
		_cfd_data.duh[i] = (*_grad_uh[i])[_qp];
	}
	_cfd_data.reinit();
	Real err =  (_cfd_data.s - _s_inf)/_s_inf;
	return err*err;
}
